//package ly.gupao.edu.spring;
//
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.AfterReturning;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.aspectj.lang.annotation.Pointcut;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Arrays;
//import java.util.HashMap;
//
///**
// * @author: liyang
// * @date：2018/6/4 0004
// * describe：
// */
//@Aspect
//@Component
//@Slf4j
//public class LogMonitor {
//
//    private Logger logger = LoggerFactory.getLogger(LogMonitor.class);
//    ThreadLocal<HashMap<String, Object>> local = new ThreadLocal<HashMap<String, Object>>();
//
//    @Pointcut("execution(* ly.gupao.edu.*.*(..))")
//    public void point(){
//    }
//
//    @Before("point()")
//    public void doBefore(JoinPoint joinPoint){
//        // 接收到请求，记录请求内容
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = attributes.getRequest();
//        HashMap<String, Object> map = new HashMap<String, Object>();
//        map.put("local", System.currentTimeMillis());
//        map.put("url", request.getRequestURL().toString());
//        map.put("ip", request.getRemoteAddr());
//        map.put("classMethod", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
//        map.put("args", Arrays.toString(joinPoint.getArgs()));
//        // 记录下请求内容
//        logger.info("URL : " + request.getRequestURL().toString());
//        logger.info("HTTP_METHOD : " + request.getMethod());
//        logger.info("IP : " + request.getRemoteAddr());
//        logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
//        logger.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
//        local.set(map);
//    }
//
//    @AfterReturning(returning = "ret", pointcut = "point()")
//    public void doAfterReturning(Object ret){
//        // 处理完请求，返回内容
//        Long executeTime = System.currentTimeMillis() - Long.valueOf(local.get().get("local").toString());
//        log.info("executeTime--:{}", executeTime);
//        log.info("url--:{}", local.get().get("url"));
//        log.info("ip--:{}", local.get().get("ip"));
//        log.info("ClassMethod--:{}", local.get().get("classMethod"));
//        log.info("Args--:{}", local.get().get("args"));
//        log.info("Response--:{}", ret);
//    }
//}
